function form_upload() {
    const form = document.forms[0];
    const upload = document.getElementById('upload');
    upload.onclick = function () {
        form.avatar.click();
    }
    form.avatar.onchange = function () {
        if (this.files.length > 0) {
            //对文件的长度做判断,单位是字节b
            if (this.files[0].size / 1024 / 1024 < 10) {
                //符合条件的，需要做本地预览
                document.querySelector('img').src = URL.createObjectURL(this.files[0]);
            } else {
                alert('图片不能大于1M')
            }
        }
    }
}
form_upload();
export default form_upload;
